<!--
 * @Author: your name
 * @Date: 2022-03-31 13:53:36
 * @LastEditTime: 2022-03-31 14:02:14
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \geyao\geyao\this指向小练习220331.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>this指向</title>
</head>

<body>
  <script>
    window.val = 1;
    var json = {
      val: 10,
      dbl: function () {
        this.val *= 2;
      },
    };
    json.dbl(); 
    console.log(json.val,"jsonval")//20
    console.log(window.val,"winval")//1
    var dbl = json.dbl;
   
    dbl();
    console.log(json.val,"jsonval")//20
    console.log(window.val,"winval")//2
    json.dbl.call(window);
    console.log(json.val,"jsonval")//20
    console.log(window.val,"winval")//4
    console.log(window.val + json.val); //24
  </script>
</body>

</html>